//
//  SEGCarRentalDetailsViewModel.m
//  Commom
//
//  Created by 梁学彰 on 2020/6/5.
//

#import "SEGCarRentalDetailsViewModel.h"

@implementation SEGCarRentalDetailsViewModel
#pragma mark - life cycle
- (instancetype)initWithRentalId:(NSString *)rentalId {
    if (self = [super init]) {
        _rentalId = rentalId;
    }
    return self;
}

#pragma mark - init


#pragma mark - send request
- (RACSignal *)sendCarDetailsRequest {
    @weakify(self);
    RACSignal *signal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
        @strongify(self);
        [[SEGDetailsellManager sharedManager] requestCarRentalDetailLeaseWithRentalid:self.rentalId finished:^(BOOL isSuccessed, SEGCarRentalDetailsDataModel *model, NSString *codeType, NSString *errorMessage) {
            if (isSuccessed) {
                //判断是否本人发 出现咨询按钮
                self.dataModel = model.data;
                self.houseImageArray = [self.dataModel.parkingPhoto componentsSeparatedByString:@","];
                [subscriber sendCompleted];
            }else {
                [subscriber sendError:[NSError errorWithDomain:errorMessage code:100 userInfo:nil]];
            }
        }];
        
        
        return nil;
    }];
    return signal;
}
#pragma mark - custom delegate

#pragma mark - system delegate

#pragma mark - event response
- (NSDictionary *)getShareParma {
    NSString* url = [NSString stringWithFormat:@"%@/h5/rent-sale-sharepage/?#/parkingRentSale?rentalId=%@&rentalType=%@&app_platform_code=%@",kClientRootURL,self.dataModel.rentalId,self.dataModel.rentalType,kAppPlatformCode];
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"shareImageUrlString"] = [NSString stringWithFormat:@"%@%@",kClientImageRootURL,self.houseImageArray.firstObject];
    param[@"sharetitle"] = self.dataModel.rentalTitle;
    param[@"sharecontent"] = self.dataModel.rentalDesc;
    
    param[@"inviteurl"] = url ?: @"";
    return param;
}
#pragma mark - private methods

#pragma mark - setter and getter
- (SEGHouseRentalAndSaleRequestManager *)requestManager {
    if (!_requestManager) {
        _requestManager = [[SEGHouseRentalAndSaleRequestManager alloc] init];
    }
    return _requestManager;
}
@end
